package com.example.ivos.vehicle.controller;

import com.example.ivos.base.response.JsonResult;
import com.example.ivos.vehicle.pojo.dto.VehicleParam;
import com.example.ivos.vehicle.pojo.dto.VehicleQuery;
import com.example.ivos.vehicle.pojo.vo.VehicleVO;
import com.example.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "车辆管理模块")
@RestController
@Slf4j
@RequestMapping("/v1/vehicle/")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;

    @ApiOperation("车辆列表")
    @GetMapping("select")
    public JsonResult select(VehicleQuery vehicleQuery){
        log.debug("控制层接口vehicleQuery：{}",vehicleQuery);
        List<VehicleVO> vechicleVOList = vehicleService.select(vehicleQuery);
        return JsonResult.ok(vechicleVOList);
    }

    @ApiOperation("添加车辆信息")
    @PostMapping("save")
    public JsonResult save(VehicleParam vehicleParam){
        log.debug("控制层接口vehicleVO：{}",vehicleParam);
        vehicleService.save(vehicleParam);
        return JsonResult.ok();
    }

    @ApiOperation("删除指定车辆")
    @PostMapping("del/{id}")
    public JsonResult del(@PathVariable Long id){
        log.debug("控制层：删除车辆id：{}",id);
        vehicleService.del(id);
        return JsonResult.ok();
    }

    @ApiOperation("车辆解绑")
    @PostMapping("unbind")
    public JsonResult unbind(Long id){
        log.debug("车辆解绑id：{}",id);
        vehicleService.unbind(id);
        return JsonResult.ok();
    }

    @ApiOperation("车辆绑定")
    @PostMapping("bind")
    public JsonResult bind(VehicleParam vehicleParam){
        log.debug("车辆绑定:{}",vehicleParam);
        vehicleService.bind(vehicleParam);
        return JsonResult.ok();
    }

}
